package hsintiao.com.xintiaoAPP.controller;

import hsintiao.com.xintiaoAPP.annotation.PassToken;
import hsintiao.com.xintiaoAPP.entity.User;
import hsintiao.com.xintiaoAPP.mapper.UserMapper;
import hsintiao.com.xintiaoAPP.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/getUserNull",method = RequestMethod.GET)
    @ResponseBody
    @PassToken
    public String getUserNull(String username){
        User byUsername = userMapper.findByUsername(username);
        System.out.println("user="+byUsername);
        System.out.println("是否为空="+(byUsername == null));
        return "Hello";
    }


    @RequestMapping(value = "/getHello",method = RequestMethod.GET)
    @ResponseBody
    public String getHello(){
        return "Hello";
    }

    @RequestMapping(value = "/getUser/{id}",method = RequestMethod.GET)
    @ResponseBody
    public User getUser(@PathVariable(name = "id") Long id){
        System.out.println("查询id="+id);
        return userService.getUserByID(id);
    }
}
